# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagraant.aws.ha3 - Install the Bigdata High Availability Server with 3 Nodes with an AWS Provider
#
# This vagrant file is meant to be launched by the bin/createCluster.sh script.
#
# The launch synopsis for this Vagrantfile:
#
#   % bin/createCluster.sh
#
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'aws'

Vagrant.require_plugin "vagrant-berkshelf"

Vagrant.configure("2") do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

config.vm.define :bigdataA do |bigdataA|
  bigdataA.vm.box = "dummy"
  bigdataA.vm.hostname = ENV['BIGDATA_HA_HOST_A']

  bigdataA.berkshelf.enabled = true

  bigdataA.vm.provider :aws do |aws, override|
    aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
    aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
    aws.keypair_name = ENV['AWS_KEYPAIR_NAME']

    aws.ami = ENV['AWS_AMI']

    aws.block_device_mapping = [
        {
            :DeviceName => "/dev/sdb", 
            :VirtualName => "ephemeral0"
        },
        {
            :DeviceName => "/dev/sdc", 
            :VirtualName => "ephemeral1"
        }
    ]
    
    aws.region = ENV['AWS_REGION']
    aws.instance_type = ENV['AWS_INSTANCE_TYPE']
    aws.security_groups = [ ENV['AWS_SECURITY_GROUPS'], ENV['AWS_SECURITY_GROUP_PRIVATE'] ]

    aws.tags = {
      'Name' => ENV['BIGDATA_HA_HOST_A']
    }

    override.ssh.username = ENV['AWS_AMI_USERNAME']
    override.ssh.private_key_path = ENV['AWS_SSH_PRIVATE_KEY']
  end

  bigdataA.vm.provision :chef_solo do |chef|
    chef.json = {
	:bigdata => {
		:install_flavor => "ha",
		:build_from_svn => true
	},
	:java => {
		:install_flavor => "oracle",
		:jdk_version => "7",
		:oracle => { 'accept_oracle_download_terms' => true }
	},
	:zookeeper =>	{
		:zoocfg => { :clientPort=> '2081' }
	}
    }

    bigdataA.vm.provision :shell, inline: "sudo apt-get update ; sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash"

    chef.run_list = [
        "recipe[bigdata::ssd]",
        "recipe[bigdata::high_availability]"
    ]

  end

end # bigdataA


config.vm.define :bigdataB do |bigdataB|
  bigdataB.vm.box = "dummy"
  bigdataB.vm.hostname = ENV['BIGDATA_HA_HOST_B']

  bigdataB.berkshelf.enabled = true

  bigdataB.vm.provider :aws do |aws, override|
    aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
    aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
    aws.keypair_name = ENV['AWS_KEYPAIR_NAME']

    aws.ami = ENV['AWS_AMI']

    aws.block_device_mapping = [
        {
            :DeviceName => "/dev/sdb", 
            :VirtualName => "ephemeral0"
        },
        {
            :DeviceName => "/dev/sdc", 
            :VirtualName => "ephemeral1"
        }
    ]
    
    aws.region = ENV['AWS_REGION']
    aws.instance_type = ENV['AWS_INSTANCE_TYPE']
    aws.security_groups = [ ENV['AWS_SECURITY_GROUPS'], ENV['AWS_SECURITY_GROUP_PRIVATE'] ]

    aws.tags = {
      'Name' => ENV['BIGDATA_HA_HOST_B']
    }

    override.ssh.username = ENV['AWS_AMI_USERNAME']
    override.ssh.private_key_path = ENV['AWS_SSH_PRIVATE_KEY']
  end

  bigdataB.vm.provision :chef_solo do |chef|
    chef.json = {
	:bigdata => {
		:install_flavor => "ha",
		:build_from_svn => true
	},
	:java => {
		:install_flavor => "oracle",
		:jdk_version => "7",
		:oracle => { 'accept_oracle_download_terms' => true }
	},
	:zookeeper =>	{
		:zoocfg => { :clientPort=> '2081' }
	}
    }

    bigdataB.vm.provision :shell, inline: "sudo apt-get update ; sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash"

    chef.run_list = [
        "recipe[bigdata::ssd]",
        "recipe[bigdata::high_availability]"
    ]

  end

end # bigdataB


config.vm.define :bigdataC do |bigdataC|
  bigdataC.vm.box = "dummy"
  bigdataC.vm.hostname = ENV['BIGDATA_HA_HOST_C']

  bigdataC.berkshelf.enabled = true

  bigdataC.vm.provider :aws do |aws, override|
    aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
    aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
    aws.keypair_name = ENV['AWS_KEYPAIR_NAME']

    aws.ami = ENV['AWS_AMI']

    aws.block_device_mapping = [
        {
            :DeviceName => "/dev/sdb", 
            :VirtualName => "ephemeral0"
        },
        {
            :DeviceName => "/dev/sdc", 
            :VirtualName => "ephemeral1"
        }
    ]
    
    aws.region = ENV['AWS_REGION']
    aws.instance_type = ENV['AWS_INSTANCE_TYPE']
    aws.security_groups = [ ENV['AWS_SECURITY_GROUPS'], ENV['AWS_SECURITY_GROUP_PRIVATE'] ]

    aws.tags = {
      'Name' => ENV['BIGDATA_HA_HOST_C']
    }

    override.ssh.username = ENV['AWS_AMI_USERNAME']
    override.ssh.private_key_path = ENV['AWS_SSH_PRIVATE_KEY']
  end

  bigdataC.vm.provision :chef_solo do |chef|
    chef.json = {
	:bigdata => {
		:install_flavor => "ha",
		:build_from_svn => true
	},
	:java => {
		:install_flavor => "oracle",
		:jdk_version => "7",
		:oracle => { 'accept_oracle_download_terms' => true }
	},
	:zookeeper =>	{
		:zoocfg => { :clientPort=> '2081' }
	}
    }

    bigdataC.vm.provision :shell, inline: "sudo apt-get update ; sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash"

    chef.run_list = [
        "recipe[bigdata::ssd]",
        "recipe[bigdata::high_availability]"
    ]

  end

end # bigdataC

end
